package com.zff.rental.utils.sql.impl;

import com.zff.rental.utils.sql.Join;
import com.zff.rental.utils.sql.JoinNext;

/**
 * @author HCY
 */
class JoinImpl extends SqlContextHolder implements Join {
    public JoinImpl(SqlContext sqlContext) {
        super(sqlContext);
    }

    @Override
    public JoinNext leftJoin(String table, String tableAlias) {
        sqlContext.getSql().append(" LEFT JOIN ").append(table);
        if (tableAlias != null) {
            sqlContext.getSql().append(" AS ").append(tableAlias);
        }
        return sqlContext.getJoinNext();
    }

    @Override
    public JoinNext rightJoin(String table, String tableAlias) {
        sqlContext.getSql().append(" RIGHT JOIN ").append(table);
        if (tableAlias != null) {
            sqlContext.getSql().append(" AS ").append(tableAlias);
        }
        return sqlContext.getJoinNext();
    }

    @Override
    public JoinNext innerJoin(String table, String tableAlias) {
        sqlContext.getSql().append(" INNER JOIN ").append(table);
        if (tableAlias != null) {
            sqlContext.getSql().append(" AS ").append(tableAlias);
        }
        return sqlContext.getJoinNext();
    }

    @Override
    public JoinNext fullJoin(String table, String tableAlias) {
        sqlContext.getSql().append(" FULL JOIN ").append(table);
        if (tableAlias != null) {
            sqlContext.getSql().append(" AS ").append(tableAlias);
        }
        return sqlContext.getJoinNext();
    }
}
